<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\AgentModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id ID
 * @property string $date 日期
 * @property string $mode 模式
 * @property string $plate_number 车牌
 * @property float $tonnage 吨位
 * @property string $loading_location 装货地点
 * @property string $customs_location 关场
 * @property string $unloading_location 卸货点
 * @property decimal $freight_rmb 运费RMB
 * @property decimal $mainland_addition_rmb 大陆加点RMB
 * @property decimal $overtime_rmb 压夜和超时RMB
 * @property decimal $no_wait_rmb 无綘RMB
 * @property decimal $parking_fee_rmb 停车费RMB
 * @property decimal $weighing_fee_rmb 过磅费RMB
 * @property decimal $registration_fee_hkd 登记费HKD
 * @property decimal $parking_fee_hkd 停车费HKD
 * @property decimal $other_hkd 其他HKD
 * @property decimal $total_cost_rmb 费用合计RMB
 * @property int $agent_id 代理商ID
 * @property string $remarks 备注
 * @property int $status 状态：1未付款 2部分付款 3已付款
 * @property float $pay_amount 已付金额
 * @property int $created_admin_id 创建人ID
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class PayableTradeModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_payble_trade';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    // 状态常量
    const STATUS_UNPAID = 1;      // 未付款
    const STATUS_PART_PAID = 2;   // 部分付款
    const STATUS_PAID = 3;        // 已付款

    const STATUS_LIST = [
        self::STATUS_UNPAID => '未付款',
        self::STATUS_PART_PAID => '部分付款',
        self::STATUS_PAID => '已付款',
    ];

    // 关联代理商
    public function agent(): BelongsTo 
    {
        return $this->belongsTo(AgentModel::class, 'agent_id');
    }

    // 关联创建人
    public function createAdmin(): BelongsTo 
    {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }
} 